export default {
	namespaced: true,
	state: () => ({
		address: JSON.parse(uni.getStorageSync('userAddress') || '{}'),
		token: uni.getStorageSync('token') || '',
		// 用户信息
		userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
		// 重定向
		redirectInfo: null
	}),
	mutations: {
		/* 
		 更新收货地址
		 */
		updateAddress(state, address) {
			state.address = address
			this.commit('m_user/addressStorage')
		},
		/* 
		 持久化存储收货地址
		 */
		addressStorage(state) {
			uni.setStorageSync('userAddress', JSON.stringify(state.address))
		},
		/* 
		 更新用户信息
		 */
		updateUserInfo(state, userInfo) {
			state.userInfo = userInfo
			this.commit('m_user/userInfoStorage')
		},
		/* 
		 用户信息持久化存储
		 */
		userInfoStorage(state) {
			uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
		},
		/* 
		 更新token
		 */
		updateToken(state, token) {
			state.token = token
			this.commit('m_user/tokenStorage')
		},
		/* 
		 token 持久化处理
		 */
		tokenStorage(state) {
			uni.setStorageSync('token', state.token)
		},
		/* 
		 更新重定向的地址
		 */
		updateRedirectInfo(state, redirect) {
			state.redirectInfo = redirect
		}
	},
	getters: {
		/* 
		 计算收货地址
		 */
		addStr(state) {
			if (!Object.values(state.address).length) return ''
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}